home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 30 / PC Gamer IT CD 30 1-2.iso / MOTS / GAMEDATA / RESOURCE / JKMRES.GOO / cog_force_pull.cog < prev    next >
Text File  |  1998-02-25  |  9KB  |  350 lines

  1. # Jedi Knight Cog Script
  2. #
  3. # FORCE_PULL.COG
  4. #
  5. # FORCEPOWER Script - Force Pull
  6. #  Basic Power
  7. #  Bin 24
  8. #
  9. # [YB]
  10. #
  11. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  12.  
  13.  
  14. symbols
  15.  
  16. template    powerup                          local
  17.  
  18. int         player                           local
  19. int         victim                           local
  20. int         potential                        local
  21. int         throwThing                       local
  22.  
  23. flex        cost=20.0                        local
  24. flex        targetcost=5                     local
  25. flex        targetcount=0                    local
  26. int         rank                             local
  27. flex        mana                             local
  28. flex        dot                              local
  29. flex        maxDot                           local
  30.  
  31. int         type                             local
  32. int         retval=0                         local
  33.  
  34. vector      dir                              local
  35.  
  36. sound       pullSound=FPush.WAV              local
  37.  
  38. int         IsAFlag=0                        local
  39.  
  40. int         inbubble=0                       local
  41.  
  42. message     startup
  43. message     activated
  44. message     deactivated
  45. message     pulse
  46. message     timer
  47. message     newplayer
  48. message     killed
  49. message     deselected
  50. message     selected
  51. message     enterbubble
  52. message     exitbubble
  53.  
  54. end
  55.  
  56. # ========================================================================================
  57.  
  58. code
  59.  
  60. startup:
  61.    player = GetLocalPlayerThing();
  62.    inbubble = 0;
  63.  
  64.    Return;
  65.  
  66. # ........................................................................................
  67.  
  68. activated:
  69.    if(inbubble) Return;
  70.  
  71.    // Cannot use power if blinded
  72.    if(GetActorFlags(player) & 0x800) Return;
  73.  
  74.    if(IsInvActivated(player, 24)) Return;
  75.  
  76.    mana = GetInv(player, 14);
  77.    rank = GetInv(player, 24);
  78.  
  79.    if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69))
  80.    {
  81.       victim = -1;
  82.       SetInvActivated(player, 24, 1);
  83.       SetPulse(0.33);
  84.       SetBinWait(player, 24, 1.0);
  85.    }
  86.    Return;
  87.  
  88. # ........................................................................................
  89.  
  90. pulse:
  91.    targetCount = targetCount + 1;
  92.    if(targetCount == 3)
  93.    {
  94.       if(GetInv(player, 64) != 1) ChangeInv(player, 14, -targetCost);
  95.       targetCount = 0;
  96.    }
  97.  
  98.    // Check all things for our victim.
  99.    victim = -1;
  100.    maxDot = 0;
  101.  
  102.    // Search for all players, actors and items.
  103.    potential = FirstThingInView(player, 20 + 15 * rank, 5.5, 0x424);
  104.    while(potential != -1)
  105.    {
  106.       if(
  107.          HasLOS(player, potential) &&
  108.          (potential != player) &&
  109.          (VectorDist(GetThingPos(player), GetThingPos(potential)) <= (0.5 + rank / 2)) &&
  110.          !(GetThingFlags(potential) & 0x200) &&
  111.          !(GetActorFlags(potential) & 0x100) &&
  112.          !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23)) &&
  113.          (GetThingMass(potential) > FLEX0) &&      // Don't pull non-physics things.
  114.          (jkGetBubbleDistance(potential) > 1.0)
  115.         )
  116.       {
  117.          // Hack to avoid targetting a CTF flag...
  118.          IsAFlag = 0;
  119.          if(GetThingType(potential) == 5)
  120.          {
  121.             if(GetItemFlags(potential) & 8)
  122.             {
  123.                IsAFlag = 1;
  124.             }
  125.          }
  126.  
  127.          if(!IsAFlag)
  128.          {
  129.             dot = ThingViewDot(player, potential);
  130.             if(dot > maxDot)
  131.             {
  132.                victim = potential;
  133.                maxDot = dot;
  134.             }
  135.          }
  136.  
  137.       }
  138.       potential = NextThingInView();
  139.    }
  140.  
  141.    // If we have a victim...
  142.    if(victim != -1)
  143.    {
  144.       jkSetTargetColors(18, 19, 20);
  145.       jkSetTarget(victim);
  146.    }
  147.    else
  148.    {
  149.       jkEndTarget();
  150.    }
  151.  
  152.    Return;
  153.  
  154. # ........................................................................................
  155.  
  156. deactivated:
  157.  
  158.    if((victim == -1) || (GetThingHealth(player) <= 0) || inbubble)
  159.    {
  160.       call stop_power;
  161.       Return;
  162.    }
  163.  
  164.    SetPulse(0);
  165.    jkEndTarget();
  166.  
  167.    mana = GetInv(player, 14);
  168.  
  169.    if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69))
  170.    {
  171.       if(HasLOS(player, victim))             // check that we still have a LOS on it...
  172.       {
  173.          PlayMode(player, 24);
  174.          PlaySoundThing(pullSound, player, 1.0, -1, -1, 0x80);
  175.          if(GetInv(player, 64) != 1) ChangeInv(player, 14, -cost);
  176.  
  177.          // Send a "force disturbance"...
  178.          if(!IsMulti())
  179.             SendMessageExRadius(GetThingPos(player), cost, 0x4, splash, 24, 0, 0, 0);
  180.  
  181.          SetBinWait(player, 24, 0.6);
  182.  
  183.          throwThing = -1;
  184.          type = GetThingType(victim);
  185.          if(type == 2)                       // ACTOR
  186.          {
  187.             if(GetActorWeapon(victim, 1) != -1)
  188.             {
  189.                // Make victim drop powerup.
  190.                throwThing = SkillTarget(victim, player, 24, 0);
  191.                if(throwThing != -1)
  192.                {
  193.                   SetActorWeapon(victim, 1, -1);
  194.                   AmputateJoint(victim, 3);
  195.                }
  196.             }
  197.             else
  198.             {
  199.                SetInvActivated(player, 24, 0);
  200.                victim = -1;
  201.                Return;
  202.             }
  203.  
  204.          }
  205.          else
  206.          if(type == 10)                      // OTHER PLAYER
  207.          {
  208.             if(!(GetThingFlags(victim) & 0x200))
  209.                retval = SkillTarget(victim, player, 24, rank);
  210.             SetInvActivated(player, 24, 0);
  211.             victim = -1;
  212.             Return;
  213.          }
  214.          else
  215.          if(type == 5)                       // ITEM
  216.          {
  217.             retval = SkillTarget(victim, player, 24, rank);
  218.             if(retval != 0)
  219.             {
  220.                if(!GetLifeLeft(victim)) SetLifeleft(victim, 30.0);
  221.                throwThing = victim;
  222.             }
  223.             else
  224.             {
  225.                SetInvActivated(player, 24, 0);
  226.                Return;
  227.             }
  228.          }
  229.  
  230.          // Throw item at player.
  231.          if(throwThing != -1)
  232.          {
  233.             type = GetThingType(throwThing);
  234.  
  235.             if(type != 2 && type != 10)   // Do not mess with actors and players!
  236.             {
  237.                SetTimerEx(1.5, 1, throwThing, 0);
  238.    
  239.                // Duplicate sends for lost packets
  240.                SetTimerEx(3.5, 2, throwThing, 0);
  241.                SetTimerEx(3.6, 2, throwThing, 0);
  242.    
  243.                if(IsMulti())
  244.                {
  245.                   // Kill the thing
  246.                   SetTimerEx(4.0, 3, throwThing, 0);
  247.                   // Duplicate send for lost packets
  248.                   SetTimerEx(4.1, 4, throwThing, 0);
  249.                }
  250.    
  251.                // Turn off gravity for the thing
  252.                ClearPhysicsFlags(throwThing, 0x1);
  253.    
  254.                dir = VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(throwThing))), 30);
  255.    
  256.                ApplyForce(throwThing, dir);
  257.             }
  258.          }
  259.       }
  260.    }
  261.  
  262.    SetInvActivated(player, 24, 0);
  263.  
  264.    Return;
  265.  
  266. # ........................................................................................
  267.  
  268. timer:
  269.  
  270.    if(GetSenderId() == 1)
  271.    {
  272.       // We MUST set gravity whatever the original setting,
  273.       // else objects might just float around...
  274.       SetPhysicsFlags(GetParam(0), 1);
  275.       Return;
  276.    }
  277.    else
  278.    if(GetSenderId() == 2)
  279.    {
  280.       // Set back to no gravity after the object had a chance to
  281.       // settle down for next time they respawn...
  282.       ClearPhysicsFlags(GetParam(0), 1);
  283.       Return;
  284.    }
  285.    else
  286.    if(GetSenderId() == 3)
  287.    {
  288.       // SITH_TF_DISABLED
  289.       SetThingFlags(GetParam(0), 0x80000);
  290.       SetLifeLeft(GetParam(0), 26);
  291.       Return;
  292.    }
  293.    else
  294.    if(GetSenderId() == 4)
  295.    {
  296.       SetThingFlags(GetParam(0), 0x80000);
  297.       SetLifeLeft(GetParam(0), 25.9);
  298.       Return;
  299.    }
  300.  
  301.    Return;
  302.  
  303. # ........................................................................................
  304.  
  305. selected:
  306.    jkPrintUNIString(player, 24);
  307.    Return;
  308.  
  309. # ........................................................................................
  310.  
  311. deselected:
  312.    call stop_power;
  313.    Return;
  314.  
  315. # ........................................................................................
  316.  
  317. killed:
  318.    if(GetSenderRef() != player) Return;
  319.  
  320. newplayer:
  321.    call stop_power;
  322.    Return;
  323.  
  324. # ........................................................................................
  325.  
  326. enterbubble:
  327.    inbubble = 1;
  328.    call stop_power;
  329.    Return;
  330.  
  331. # ........................................................................................
  332.  
  333. exitbubble:
  334.    inbubble = 0;
  335.    Return;
  336.  
  337. # ........................................................................................
  338.  
  339. stop_power:
  340.    SetPulse(0);
  341.    SetInvActivated(player, 24, 0);
  342.    victim = -1;
  343.    jkEndTarget();
  344.  
  345.    Return;
  346.  
  347. end
  348.  
  349.  
  350.